﻿var wmsBiz = new Object();
//保存
wmsBiz.saveAndTip = function (dataModel) {
    var rtn = wmsCommon.pubSaveMethod(dataModel);   //调用通用保存方法
    if (wmsCommon.checkForNull(rtn) == "") {
        wmsCommon.alert("信息保存失败，请与管理员联系！");
    }
    else {
        wmsCommon.alert("信息保存成功！");
    }
}

wmsBiz.setObjText = function (obj, i, text) {
    if (obj[i].firstChild && obj[i].firstChild.childNodes.length > 0)  //兼容嵌套的<nobr>及其他单层节点
        obj[i].firstChild.firstChild.nodeValue = text;
    else
        obj[i].innerText = wmsCommon.checkForNull(text);
}

wmsBiz.setObjValue = function (obj, i, text) {
    obj[i].childNodes[0].childNodes[0].value = wmsCommon.checkForNull(text.toString());
}
wmsBiz.DropLastSymbol = function (express) {
    if (wmsCommon.checkForNull(express) == "") return "";
    if (express.length > 0)
        return express.substring(0, express.length - 1);
}

//open user role's authorization page
wmsBiz.openUsRoleAutorization = function (obj) {
    var userNo = obj.parentNode.id;
    var userName = obj.parentNode.name;
    var href = "Pages/userDeptRoleAtuthorizationMain.htm?" + "userNo=" + encodeURIComponent(userNo) + "&userName=" + encodeURIComponent(userName);
    wmsCommon.openWin(href, '800', "600");
}


//跳转到我的周面
wmsBiz.myDeskTop = function () {
    var rootPath = wmsCommon.getRootPath();
    window.parent.parent.frames["main"].location.href = rootPath + "/fDefault.htm";
    window.parent.parent.frames["mapBar"].location.href = rootPath + "/SiteMapBar.htm?barMsg=我的信息平台";
}


//删除部门
wmsBiz.deleteDepartment = function (tableID, modelName) {
    debugger;
    var allSelectedRow = wmsCommon.getSelectedKeyValues(tableID);
    if (wmsCommon.checkForNull(allSelectedRow) != "") {
        if (confirm("是否确定要删除选择的信息？")) {
            var result = wmsCommon.execCommand(String.format("sys(#DepartmentManager.DeleteDeparment({0}))", escape(allSelectedRow)));
            if (result.length > 0) {
                var reArr = result.substring(0, result.length - 1).split(',');
                var message = "";
                for (var i = 0; i < reArr.length; i++) {
                    if (reArr[i].split('=')[1].split('&')[1] == 'true') {
                        message += reArr[i].split('=')[1].split('&')[0] + "删除成功!\n";
                    }
                    else {
                        message += reArr[i].split('=')[1].split('&')[0] + " 有子部门不能被删除!\n";
                    }
                }
                alert(message);
            }
            wmsCommon.refThisPage();
        }
    }
    else {
        wmsCommon.alert("请先选择需要删除的信息！");
    }
}

//删除角色
wmsBiz.deleteRoles = function (tblID) {
    var prometText = "删除该角色,将会删除所有用户的该角色权限,确定要删除?";
    wmsCommon.relatedDelete(tblID, "roleinfo,roleModules", prometText);
}
//删除用户 一并删除其角色
wmsBiz.deleteUser = function (tblID) {
    var prometText = "删除用户,将会删除用于对应角色权限,确定删除?";
    wmsCommon.relatedDelete(tblID, "userinfo,userroleinfo", prometText);
}

//删除物料分类前校验
wmsBiz.deleteMaterial_Categories = function (tableID) {
    var allSelectedRow = wmsCommon.getSelectedKeyValues(tableID);
    if (wmsCommon.checkForNull(allSelectedRow) != "") {
        if (confirm("是否确定要删除选择的信息？")) {
            var keyColumns = allSelectedRow.replace(/,/g, "|");
            var ifSucc = wmsCommon.execCommand(String.format("sys(#MaterialManager.CheckMaterial_Categories({0}))", keyColumns));
            if (ifSucc == "1") {
                wmsCommon.refParentPage();
            }
            else if (ifSucc == "2") {
                wmsCommon.alert("被物料使用的物料类型和有子集的物料类型不允许删除！");
                wmsCommon.refParentPage();
            }
            else {
                wmsCommon.alert("删除失败，请与管理员联系！");
            }
        }
    }
}

//临时测试用，可删
wmsBiz.executeIn = function (obj) {
    var keyValue = obj.parentNode.parentNode.keyvalue;
    var result = wmsCommon.execCommand(String.format(" sys(#TaskManagerCE.ExecuteIn({0})) ", keyValue));
    if (result != '0') {
        wmsCommon.alert("执行完成！");
        wmsCommon.refThisPage();
    } else {
        wmsCommon.alert("执行失败！");
    }
}

//  obj:一般用this） model:对应的xml模型名称  temp: html模板名称
wmsBiz.openLookWin = function (keyvalue, model, temp, width, hight) {

    if (wmsCommon.getSessionValue("userNo") == "") {
        wmsCommon.timeOut();
        return;
    }
    if (wmsCommon.checkForNull(keyvalue) == "") return;
    if (wmsCommon.checkForNull(temp) == "") return;
    if (wmsCommon.checkForNull(model) == "") return;
    if (wmsCommon.checkForNull(width) == "") width = 800;
    if (wmsCommon.checkForNull(hight) == "") hight = 600;
    var rootPath = wmsCommon.getRootPath();
    wmsCommon.openWin(rootPath + "/model.aspx?model=" + model + "&temp=" + temp, width, hight);
}

//功能：截取内容的 leng长度
//参数：content:内容,leng：要截取的长度
wmsBiz.subContent = function (content, length) {
    if (content && content.toString().length > length) {
        return content.substr(0, length)+"...";
    }
    return content;
}


//处理TextArea
wmsBiz.dealWithTextAreas = function (objs) {
    if (!objs) return false;
    var textAreas = $(objs);
    textAreas.css("height", 30);
    for (var i = 0; i < textAreas.length; i++) {
        var ta = $(textAreas[i]);
        ta.attr("title", ta.html());
        wmsBiz.textAreaBindMouseOnver(ta);
    }
}


///textArea绑定鼠标移入事件，用来实时的更新TextArea的Title
wmsBiz.textAreaBindMouseOnver=function (obj) {
    if (!obj) return;
    $(obj).bind("mouseover", function (event) { //重新绑定titile
        var evt = event || window.event;
        var eventOjb = evt.target || evt.srcElement;
        if (!eventOjb) return false;
        $(eventOjb).attr("title", $(eventOjb).html());
    });
}


//周报编辑界面的初始化和级联效果
wmsBiz.childActityInit = function () {
    $("textarea").css("height", "30px");
    $("textarea").css("width", "300px");
    $("select").css("width", "100px");
    $("#weekReportItems :text").css("width", "100px");
    var trL = $("#weekReportItems tr");
    for (var j = 1; j < trL.length; j++) {
        var selectL = $(trL[j]).find("select");
        var option2L1 = $(selectL[1]).find("option").clone();
        var var0 = $(selectL[0]).val();
        var val1 = $(selectL[1]).val();
        if ($(selectL[1]).val() != "") {
            $(selectL[1]).empty();
            $(selectL[1]).append("<option value=''>请选择</option>");
            for (var i = 0; i < option2L1.length; i++) {
                if (var0 == $(option2L1[i]).val().split("-")[0]) {
                    $(selectL[1]).append(option2L1[i]);
                }
            }
            $(selectL[1]).val(val1);
        }
        $(selectL[0]).bind("change", function () {//当活动类型改变时加载对应的子活动类型，级联效果
            var option2L2 = option2L1.clone();
            var select1 = $(this).parent().parent().next().find("select");
            select1.empty();
            select1.append("<option value='' selected='selected'>请选择</option>");
            for (var i = 0; i < option2L2.length; i++) {
                if ($(this).val() == $(option2L2[i]).val().split("-")[0]) {
                    select1.append(option2L2[i]);
                }
            }
        })
    }
}